﻿using Abp.Domain.Entities.Auditing;
using Microsoft.EntityFrameworkCore;
using shenghua.Common.CustomValueType;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace shenghua.Order.Orders.Median
{
    /// <summary>
    /// 订单信息
    /// </summary>
    [Owned]
    public class OrderInfo: IHasCreationTime
    {
        /// <summary>
        /// 总金额
        /// </summary>
        public Money TotalAmount
        {
            get
            {
                return CommodityTotalAmount - CouponAmount - XPAmount + FreightAmount + AdjustmentAmount;
            }
        }

        /// <summary>
        /// 商品总金额
        /// </summary>
        public Money CommodityTotalAmount { get; set; }

        /// <summary>
        /// 商品总数量
        /// </summary>
        public int CommodityTotalCount { get; set; }

        /// <summary>
        /// 优惠券抵消掉的金额
        /// </summary>
        public Money CouponAmount { get; set; }

        /// <summary>
        /// 使用的优惠券ID
        /// </summary>
        public int? CouponId { get; set; }

        /// <summary>
        /// 使用的优惠券描述
        /// </summary>
        public string CouponProfile { get; set; }

        /// <summary>
        /// 积分抵消掉的金额
        /// </summary>
        public Money XPAmount { get; set; }

        /// <summary>
        /// 使用的积分值
        /// </summary>
        public int UsedXPValue { get; set; }

        /// <summary>
        /// 可获得的积分值
        /// </summary>
        public int BounsXPValue { get; set; }

        /// <summary>
        /// 运费
        /// </summary>
        public Money FreightAmount { get; set; }

        /// <summary>
        /// 订单名称
        /// </summary>
        public string Subject { get; set; }

        /// <summary>
        /// 订单描述
        /// </summary>
        public string Description { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Remark { get; set; }

        /// <summary>
        /// 管理员备注
        /// </summary>
        public string AdminRemark { get; set; }

        /// <summary>
        /// 管理员调整的金额，可正可负
        /// </summary>
        public Money AdjustmentAmount { get; set; }

        public OrderStatus Status { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime CreationTime { get; set; }
        /// <summary>
        /// 付款时间
        /// </summary>
        public DateTime PaymentTime { get; set; }
        /// <summary>
        /// 发货时间
        /// </summary>
        public DateTime ShipTime { get; set; }
        /// <summary>
        /// 成交时间
        /// </summary>
        public DateTime FinishedTime { get; set; }

        public OrderInfo()
        {
            CommodityTotalAmount = new Money();
            CouponAmount = new Money();
            XPAmount = new Money();
            FreightAmount = new Money();
            AdjustmentAmount = new Money();
        }
    }

    /// <summary>
    /// 订单状态
    /// </summary>
    public enum OrderStatus
    {
        /// <summary>
        /// 已创建
        /// </summary>
        Created,
        /// <summary>
        /// 已成功
        /// </summary>
        Succeeded,
        /// <summary>
        /// 已关闭
        /// </summary>
        Closed
    }
}
